package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GatherTask;
import com.ruoyi.system.service.IGatherTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集任务Controller
 * 
 * @author ruoyi
 * @date 2023-11-06
 */
@RestController
@RequestMapping("/system/task_gather")
public class GatherTaskController extends BaseController
{
    @Autowired
    private IGatherTaskService gatherTaskService;

    /**
     * 查询采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:task_gather:list')")
    @GetMapping("/list")
    public TableDataInfo list(GatherTask gatherTask)
    {
        startPage();
        List<GatherTask> list = gatherTaskService.selectGatherTaskList(gatherTask);
        return getDataTable(list);
    }

    /**
     * 查询采集任务列表
     */
    @GetMapping("/listForAnonymous")
    public TableDataInfo listForAnonymous(GatherTask gatherTask)
    {
        startPage();
        List<GatherTask> list = gatherTaskService.selectGatherTaskList(gatherTask);
        return getDataTable(list);
    }
    /**
     * 导出采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:task_gather:export')")
    @Log(title = "采集任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GatherTask gatherTask)
    {
        List<GatherTask> list = gatherTaskService.selectGatherTaskList(gatherTask);
        ExcelUtil<GatherTask> util = new ExcelUtil<GatherTask>(GatherTask.class);
        return util.exportExcel(list, "采集任务数据");
    }

    /**
     * 获取采集任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:task_gather:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gatherTaskService.selectGatherTaskById(id));
    }

    /**
     * 新增采集任务
     */
    @PreAuthorize("@ss.hasPermi('system:task_gather:add')")
    @Log(title = "采集任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GatherTask gatherTask)
    {
        return toAjax(gatherTaskService.insertGatherTask(gatherTask));
    }



    /**
     * 修改采集任务
     */
    @PreAuthorize("@ss.hasPermi('system:task_gather:edit')")
    @Log(title = "采集任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GatherTask gatherTask)
    {
        return toAjax(gatherTaskService.updateGatherTask(gatherTask));
    }

    /**
     * 修改采集任务(任何人)
     */
    @Log(title = "采集任务", businessType = BusinessType.UPDATE)
    @PutMapping("/updateGatherTask")
    public AjaxResult updateGatherTask(@RequestBody GatherTask gatherTask)
    {
        return toAjax(gatherTaskService.updateGatherTask(gatherTask));
    }


    /**
     * 删除采集任务
     */
    @PreAuthorize("@ss.hasPermi('system:task_gather:remove')")
    @Log(title = "采集任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gatherTaskService.deleteGatherTaskByIds(ids));
    }
}
